import 'package:flutter/material.dart';

// 11111 顶部普通导航栏的key
GlobalKey<_GoodsDetailAppBarState> goodsDetailAppBarKey = GlobalKey(
  debugLabel: 'goodsDetailAppBarKey',
);

class GoodsDetailAppBar extends StatefulWidget {
  // 22222 构造函数 用于传递Key
  const GoodsDetailAppBar({super.key});

  @override
  _GoodsDetailAppBarState createState() => _GoodsDetailAppBarState();
}

class _GoodsDetailAppBarState extends State<GoodsDetailAppBar> {
  // 55555 设置私有属性opacity
  double _opacity = 1.0;

  // 33333 定义获取顶部导航栏透明图的方法
  void getGoodsDetailAppBarOpacity(double opacity) {
    _opacity = 1.0 - opacity;
    debugPrint('获取顶部导航栏透明图的方法$opacity');
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    // 顶部导航栏高度 = 顶部工具栏高度 + 不规则屏幕上边距
    double appBarHeight = kToolbarHeight + MediaQuery.of(context).padding.top;

    return Opacity(
      opacity: _opacity, // 普通导航栏从1.0~0.0变化
      child: Container(
        height: appBarHeight,
        child: SafeArea(
          child: Container(
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.only(left: 18.0),
            child: GestureDetector(
              onTap: () {
                Navigator.pop(context);
              },
              child: Image.asset('assets/fanhui_float.png'),
            ),
          ),
        ),
      ),
    );
  }
}
